package com.newzqxq.koalamoney.ui.activity;

import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.newzqxq.koalamoney.R;
import com.newzqxq.koalamoney.common.BaseActivity;
import com.newzqxq.koalamoney.widget.ColorTextView;
import com.newzqxq.koalamoney.widget.progress.ProgressRing;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 产品详情
 * Created by ZQXQ-Developer on 2017/7/17.
 */

public class ProductDetailsActivity extends BaseActivity {

    @BindView(R.id.title_relative_back)
    RelativeLayout rlBack;

    @BindView(R.id.title_mid_tv)
    TextView tvTitle;

    @BindView(R.id.progressRing)
    ProgressRing progressRing;
    @BindView(R.id.tvPostNo)
    TextView tvPostNo;//投递数量

    @BindView(R.id.tvCountDown)
    TextView tvCountDown;


    Timer timer = new Timer();

    private int reclen = 60;

    @Override
    protected int getContentViewId() {
        return R.layout.ui_product_details;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        tvTitle.setText(R.string.product_details);
        progressRing.setProgress(60);
        String pattern = "剩余可投: {" + 13600 + "}/" + 50000 + "(元)";
        CharSequence chars = ColorTextView.from(pattern).withSeparator("{}")
                .innerColor(0xFFE6454A).outerColor(0xFF666666).format();
        tvPostNo.setText(chars);
        timer.schedule(task, 1000, 1000);
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void clearMemory() {

    }

    @OnClick({R.id.title_relative_back, R.id.llRecord,
            R.id.borrowInfo, R.id.tvAdds})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_relative_back:
                finish();
                break;
            case R.id.llRecord:
                startActivity(new Intent(this, InvestRecordActivity.class));
                break;
            case R.id.borrowInfo:
                startActivity(new Intent(this, BorrowInfoActivity.class));
                break;
            case R.id.tvAdds://立即加入
                startActivity(new Intent(this, InvestActivity.class));
                break;
        }
    }

    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    reclen--;
                    tvCountDown.setText("" + reclen);
                    if (reclen < 0) {
                        timer.cancel();
                        tvCountDown.setText("00:00:00");
                    }
                }
            });
        }
    };
}
